home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / main20.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  5KB  |  233 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32. #include "music.h"
  33.  
  34. void quit()
  35. {
  36.     int a;
  37.  
  38.     remclock();
  39.     removehotkeys();
  40.     endnotifies();
  41.  
  42.     if (keyboard_req) {
  43.         CloseDevice((struct IORequest *)keyboard_req);
  44.         LDeleteExtIO((struct IORequest *)keyboard_req);
  45.     }
  46.     if (input_req) {
  47.         CloseDevice((struct IORequest *)input_req);
  48.         LDeleteExtIO((struct IORequest *)input_req);
  49.     }
  50.  
  51.     close_rexx_port();
  52.  
  53.     main_proc->pr_WindowPtr=windowptr_save;
  54.     closedisplay();
  55.  
  56.     remove_arbiter();
  57.  
  58.     allocdirbuffers(0);
  59.     for (a=0;a<2;a++) {
  60.         freedir(dopus_specialwin[a],-1);
  61.         LFreeRemember(&completion[a].memory);
  62.     }
  63.     if (dir_memory_pool) LibDeletePool(dir_memory_pool);
  64.     for (a=0;a<NUMFONTS;a++) freefont(a);
  65.     freedynamiccfg();
  66.     freehelp();
  67.     LFreeRemember(&general_key);
  68.     LFreeRemember(&border_key);
  69.     LFreeRemember(&menu_key);
  70.     FreeStringFile(&stringdata);
  71.  
  72.     if (configopus_segment) UnLoadSeg(configopus_segment);
  73.     for (a=0;a<3;a++) {
  74.         if (external_mod_segment[a]) UnLoadSeg(external_mod_segment[a]);
  75.     }
  76.  
  77.     if (nil_file_handle) Close(nil_file_handle);
  78.     if (ramdisk_lock) UnLock(ramdisk_lock);
  79.     if (func_reselection.reselection_list)
  80.         FreeMem(func_reselection.reselection_list,func_reselection.reselection_size);
  81.     if (count_port) LDeletePort(count_port);
  82.     if (arexx_port) LDeletePort(arexx_port);
  83.     if (general_port) LDeletePort(general_port);
  84.     if (appmsg_port) LDeletePort(appmsg_port);
  85.  
  86.     if (IconBase) CloseLibrary(IconBase);
  87.     if (DiskfontBase) CloseLibrary(DiskfontBase);
  88.     if (PPBase) CloseLibrary(PPBase);
  89.     if (WorkbenchBase) CloseLibrary(WorkbenchBase);
  90.     if (CxBase) CloseLibrary(CxBase);
  91.     if (RexxSysBase) CloseLibrary(RexxSysBase);
  92.     if (UtilityBase) CloseLibrary(UtilityBase);
  93.     if (AccountsBase) {
  94.         if (user_info) FreeUserInfo(user_info);
  95.         if (group_info) FreeGroupInfo(group_info);
  96.         CloseLibrary(AccountsBase);
  97.     }
  98.     if (MUSICBase) {
  99.         FlushModule();
  100.         CloseLibrary(MUSICBase);
  101.     }
  102.  
  103.     if (DOpusBase) CloseLibrary((struct Library *) DOpusBase);
  104.  
  105.     main_proc->pr_CIS=old_pr_cis;
  106.     main_proc->pr_COS=old_pr_cos;
  107.     main_proc->pr_ConsoleTask=old_pr_consoletask;
  108.  
  109. #ifdef __SASC_60
  110.         __exit(0);
  111. #else
  112.         _exit(0);
  113. #endif
  114. }
  115.  
  116. void remclock()
  117. {
  118.     if (clockmsg_port) {
  119.         dotaskmsg(clockmsg_port,TASK_QUIT,0,0,NULL,0);
  120.         DeleteTask(clock_task); clock_task=NULL;
  121.     }
  122. }
  123.  
  124. void removehotkeys()
  125. {
  126.     if (hotkeymsg_port) {
  127.         dotaskmsg(hotkeymsg_port,TASK_QUIT,0,0,NULL,0);
  128.         DeleteTask(hotkey_task); hotkey_task=NULL;
  129.     }
  130. }
  131.  
  132. void freefont(num)
  133. int num;
  134. {
  135.     if (scr_font[num]) CloseFont(scr_font[num]);
  136.     scr_font[num]=NULL;
  137. }
  138.  
  139. void freehelp()
  140. {
  141.     LFreeRemember(&help_key);
  142.     dopus_firsthelp=NULL;
  143. }
  144.  
  145. void freedynamiccfg()
  146. {
  147.     struct ConfigStuff cstuff;
  148.  
  149.     fixcstuff(&cstuff);
  150.     FreeConfig(&cstuff);
  151.     cstufffix(&cstuff);
  152. }
  153.  
  154. checkwindowquit()
  155. {
  156.     struct Window *wind,*temp;
  157.     int a;
  158.  
  159.     a=1;
  160.     if (!MainScreen) return(1);
  161.     wind=MainScreen->FirstWindow;
  162.     while (wind) {
  163.         if (wind!=Window) {
  164.             a=0;
  165.             break;
  166.         }
  167.         wind=wind->NextWindow;
  168.     }
  169.     if (a) return(1);
  170.     busy();
  171.     if (!(simplerequest(globstring[STR_ALIEN_WINDOWS],globstring[STR_CLOSE],
  172.         str_cancelstring,NULL))) {
  173.         unbusy();
  174.         return(0);
  175.     }
  176.     wind=MainScreen->FirstWindow;
  177.     while (wind) {
  178.         temp=wind->NextWindow;
  179.         if (wind!=Window) CloseWindow(wind);
  180.         wind=temp;
  181.     }
  182.     unbusy();
  183.     return(1);
  184. }
  185.  
  186. void dotaskmsg(port,command,value,total,data,flag)
  187. struct MsgPort *port;
  188. int command,value,total;
  189. char *data;
  190. int flag;
  191. {
  192.     if (port) {
  193.         struct dopustaskmsg taskmsg;
  194.  
  195.         taskmsg.msg.mn_Node.ln_Type=NT_MESSAGE;
  196.         taskmsg.msg.mn_ReplyPort=general_port;
  197.         taskmsg.msg.mn_Length=(UWORD)sizeof(struct dopustaskmsg);
  198.         taskmsg.command=command;
  199.         taskmsg.value=value;
  200.         taskmsg.total=total;
  201.         taskmsg.data=data;
  202.         taskmsg.flag=flag;
  203.         PutMsg(port,(struct Message *)&taskmsg);
  204.         WaitPort(general_port);
  205.         GetMsg(general_port);
  206.     }
  207. }
  208.  
  209. void closedisplay()
  210. {
  211.     if (status_iconified) cleanupiconify();
  212.     else {
  213.         if (MainScreen) ScreenToBack(MainScreen);
  214.         freedragbuffers();
  215.         Forbid();
  216.         if (Window) {
  217.             if (Window->MenuStrip) ClearMenuStrip(Window);
  218.             if (WorkbenchBase && dopus_appwindow) {
  219.                 RemoveAppWindow(dopus_appwindow);
  220.                 dopus_appwindow=NULL;
  221.             }
  222.             free_colour_table();
  223.             CloseWindow(Window);
  224.             Window=NULL;
  225.         }
  226.         if (MainScreen) {
  227.             CloseScreen(MainScreen);
  228.             MainScreen=NULL;
  229.         }
  230.         Permit();
  231.     }
  232. }
  233.